﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCar.aspx.cs" Inherits="CNVP.JShop.Web.Member.ShoppingCar" %><%@ Register src="Footer.ascx" tagname="Footer" tagprefix="uc1" %>
<%@ Register src="Header.ascx" tagname="Header" tagprefix="uc1" %>
<%@ Register src="LeftNav.ascx" tagname="LeftNav" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>购物车</title>
    <link href="css/Global.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/Fonts.css" rel="stylesheet" type="text/css" media="all"  />
<link href="css/Style.css" rel="stylesheet" type="text/css" media="all" />
<link href="../CSS/MemberCenter.css" rel="stylesheet" type="text/css" media="all" />
    <script src="../Scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/procp.js"></script>
    <script src="../Scripts/Common.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
<uc1:Header ID="Header1" runat="server" />
<div class="Width MBody clearfix">
    <div class="MRightTitle"><p>购物车</p></div>
         <div class="MRightBox">
             <asp:Label ID="lbShoppingCar" runat="server"></asp:Label>
            <div id="InfoCar" runat="server">
             <input id="btnDelete" type="button" value="清 空" runat="server" onclick="DelAll()" />
            <input id="btnGoPay" type="button" value="去结账" runat="server" onclick="GoPay()" />
            购物车里有商品: 
            <asp:Label ID="lbSumNum" runat="server" Text="0"></asp:Label>
            件 总计:
            <asp:Label ID="lbTotalMoney" runat="server" Text="0" CssClass="ProductPrice"></asp:Label>
            元 
            </div>
       </div>
</div>
    <script type="text/javascript">
        function Del(proId,proDetailId) {
            if (ifShoppingCar()) {
                if (confirm("你确定要删除该记录吗？")) {
                    var Num = document.getElementById("Num" + proId + "_" + proDetailId + "").value;
                    GetAjaxResponse("../Controls/AjaxProDetailNum.aspx?OperType=Delete&ProID=" + proId + "&ProDetailID=" + proDetailId + "&CompareValue=" + Num);
                    $("#tr" + proId + "_" + proDetailId + "").remove();
                }
                TotalCount();
            }
            else {
                alert('请选择记录！');
                return false;
            }
        }
        function DelAll() {
            if (ifShoppingCar()) {
                if (confirm("你确定要清除该记录吗？")) {
                    var cbCheck = document.getElementsByName("cbCheck");
                    for (var i = 0; i < cbCheck.length; i++) {
                        if (cbCheck[i].checked == true) {
                            var Num = document.getElementById("Num" + cbCheck[i].value + "").value;
                            GetAjaxResponse("../Controls/AjaxProDetailNum.aspx?OperType=Delete&ProDetailID=" + cbCheck[i].value + "&CompareValue=" + Num);
                            $("#tr" + cbCheck[i].value + "").remove();
                            i--;
                        }
                    }
                }
                TotalCount();
            }
            else {
                alert('请选择记录！');
                return false;
            }
        }
        function ProductsOnchang(proId, proDetailId,DisCountPercent) {
            var Allprice = 0.00;
            var Num = document.getElementById("Num" + proId + "_" + proDetailId + "").value;
            var NumCompare = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
            var Price = document.getElementById("Price" + proId + "_" + proDetailId + "").innerHTML;
            var spantotalPrice = document.getElementById("spantotalPrice" + proId + "_" + proDetailId + "");
            var totalPrice = document.getElementById("totalPrice" + proId + "_" + proDetailId + "");
            if (Num > 0) {
                var NumState = GetAjaxResponse("../Controls/AjaxProDetailNum.aspx?OperType=Update&ProID=" + proId + "&ProDetailID=" + proDetailId + "&CompareValue=" + Num);
                 if (NumState == "0") {
                     alert("库存不足！");
                     document.getElementById("Num" + proId + "_" + proDetailId + "").value = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
                     Allprice = parseInt(NumCompare) * parseFloat(Price) * DisCountPercent;
                     spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                     totalPrice.value = Math.round(Allprice * 100) / 100;
                 }
                 else {
                     Allprice = parseInt(Num) * parseFloat(Price) * DisCountPercent;
                     spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                     totalPrice.value = Math.round(Allprice * 100) / 100;
                 }
            }
            else {
                alert("请输入0的整数！");
                document.getElementById("Num" + proId + "_" + proDetailId + "").value = document.getElementById("NumCompare" + proId + "_" + proDetailId + "").value;
                Allprice = parseInt(NumCompare) * parseFloat(Price) * DisCountPercent;
                spantotalPrice.innerHTML = Math.round(Allprice * 100) / 100;
                totalPrice.value = Math.round(Allprice * 100) / 100;
            }
            TotalCount();
        }
        function TotalCount() {
            var getNum = 0;
            var getTotalList = 0.00;
            var getTotalPrice = document.getElementsByName("totalPrice");
            var cbCheck = document.getElementsByName("cbCheck");
            var lbSumNum = document.getElementById("<%=lbSumNum.ClientID %>");
            var lbTotalMoney = document.getElementById("<%=lbTotalMoney.ClientID %>");
            var lbShoppingCar = document.getElementById("<%=lbShoppingCar.ClientID %>");
            if (cbCheck.length > 0) {
                for (var i = 0; i < cbCheck.length; i++) {
                    var Num = document.getElementById("Num" + cbCheck[i].value + "").value;
                    if (cbCheck[i].checked == true) {
                        getNum += parseInt(Num);
                        getTotalList += parseFloat(getTotalPrice[i].value);
                    }
                }
            }
            else {
                var AddTr = "";
                AddTr += "      <table class=\"ListTable\" id=\"tableEdit\" Width=\"100%\">";
                AddTr += "        <tr>";
                AddTr += "            <td colspan=\"2\" align=\"right\" >";
                AddTr += "             <img src=\"../images/car.png\" style=\"padding:20px 0px 20px 0px;\" /></td>";
                AddTr += "            <td colspan=\"5\" align=\"left\">";
                AddTr += "             <b style=\"font-size:18px;\">您的购物车还是空的，赶紧行动吧！您可以：</b><br/>";
                AddTr += "             &nbsp;&nbsp;&nbsp;<b>马上去</b>&nbsp;&nbsp;<a href =\"../\">挑选宝贝</a> <br/> ";
                AddTr += "             &nbsp;&nbsp;&nbsp;<b>看看</b>&nbsp;&nbsp;<a href =\"OrderList.aspx\">查看买到的宝贝</a>  ";
                AddTr += "                </td>";
                AddTr += "            <td>";
                AddTr += "        </tr>";
                AddTr += "    </table>";
                lbShoppingCar.innerHTML = AddTr;
                $("#InfoCar").css("display", "none");
            }
            lbSumNum.innerHTML = getNum;
            lbTotalMoney.innerHTML = Math.round(getTotalList * 100) / 100;
        }
        function GoPay() {
            if (ifShoppingCar()) {
                var getNumArray = "";
                var getIdArray = "";
                var getProIDArray = "";
                var cbCheck = document.getElementsByName("cbCheck");
                for (var i = 0; i < cbCheck.length; i++) {
                    var Num = document.getElementById("Num" + cbCheck[i].value + "").value;
                    var ProIDS = document.getElementById("ProID" + cbCheck[i].value + "").value;
                    var ProDetailIDS = document.getElementById("ProDetailID" + cbCheck[i].value + "").value;
                    if (cbCheck[i].checked == true) {
                        //alert(cbCheck[i].value);
                        getNumArray += Num + ",";
                        getIdArray += ProDetailIDS + ","; //详细表IDS
                        getProIDArray += ProIDS + ",";//主表IDS
                    }
                }
                getNumArray = getNumArray.substring(0, getNumArray.length - 1);
                getIdArray = getIdArray.substring(0, getIdArray.length - 1);
                getProIDArray = getProIDArray.substring(0, getProIDArray.length - 1);
                location.replace("OrderAdd.aspx?SaleNumArray=" + getNumArray + "&ProductIDS=" + getProIDArray + "&ProDetailIDS=" + getIdArray);
            }
            else {
                alert('请选择记录！');
                return false;
            }
        }
    </script>
    <script type="text/javascript">
       jQuery(document).ready(CheckUserLogin); 
    </script>
    <uc1:Footer ID="Footer1" runat="server" />
    </form>
</body>
</html>